package com.tianbing.adlottery.controller.hordeadmin;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.validation.BindException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.fengniu.ejb.business.ICategoryBusiness;
import com.fengniu.ejb.business.IContentBusiness;
import com.fengniu.ejb.business.IUserBusiness;
import com.fengniu.ejb.dao.ICategoryDao;
import com.fengniu.ejb.dao.IUserDao;
import com.fengniu.ejb.entity.User2Site;
import com.tianbing.adlottery.helper.SkinUtils;
import com.tianbing.adlottery.util.ControllerFormBean;
import com.tianbing.adlottery.util.UserSession;

public class EditApproveMyServedStoreController extends SimpleFormController {
	static Logger logger = Logger.getLogger(EditApproveMyServedStoreController.class.getName());

	private IUserDao userDao;

	private SkinUtils skinUtils;

	private ICategoryDao categoryDao;

	private IUserBusiness userBusiness;

	private ICategoryBusiness categoryBusiness;

	private IContentBusiness contentBusiness;

	// ------------------GET Request LifeCycle------------------
	protected Object formBackingObject(HttpServletRequest request) throws Exception {
		ControllerFormBean fb = new ControllerFormBean();
		long u2ssid = ServletRequestUtils.getLongParameter(request, "u2ssid", -1);
		User2Site user2Site = userDao.findUser2SiteBy(u2ssid);
		fb.setUser2Site(user2Site);
		return fb;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
	 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
	 *      org.springframework.validation.BindException)
	 */
	protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object cmd,
			BindException ex) throws Exception {
		String cgid = ServletRequestUtils.getStringParameter(request, "cgid", null);
		String brandCategoryId = ServletRequestUtils.getStringParameter(request, "brandCategoryId", null);

		UserSession auth = skinUtils.getUserAuthorization(request, null);
		ModelAndView mv = new ModelAndView(this.getSuccessView());
		ControllerFormBean form = (ControllerFormBean) cmd;
		User2Site u2s = form.getUser2Site();
		userBusiness.approveUserServedStore(auth.getUserSysId(), u2s);
		return mv;
	}

	protected Map referenceData(HttpServletRequest request) throws Exception {
		Map model = new HashMap();

		return model;
	}

	public static void setLogger(Logger logger) {
		EditApproveMyServedStoreController.logger = logger;
	}

	public void setUserDao(IUserDao userDao) {
		this.userDao = userDao;
	}

	public void setSkinUtils(SkinUtils skinUtils) {
		this.skinUtils = skinUtils;
	}

	public void setCategoryDao(ICategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	public void setUserBusiness(IUserBusiness userBusiness) {
		this.userBusiness = userBusiness;
	}

	public void setCategoryBusiness(ICategoryBusiness categoryBusiness) {
		this.categoryBusiness = categoryBusiness;
	}

	public void setContentBusiness(IContentBusiness contentBusiness) {
		this.contentBusiness = contentBusiness;
	}

}
